<template>
    <div>
        <el-form :model="newsForm" label-width="120px" :rules="newsFormRules" ref="newsFormRef">         
            <el-form-item label="内容" prop="content">
                <editor @event="handleChange"></editor>
            </el-form-item>
            
            <el-form-item label="">
              <el-button type="primary" @click="submitForm()">添加</el-button>
            </el-form-item>
          </el-form>
    </div>
</template>

<script setup>
import {ref,reactive} from 'vue'
import editor from '../../components/editor/editor.vue'
import { Plus, } from "@element-plus/icons-vue";
import upload from '@/util/upload';
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";
const router = useRouter();
import axios from "axios"
const newsFormRef = ref();
const newsForm = reactive({
 
    content:"",
    
})
const handleChange = (data)=> {
    newsForm.content = data;
    console.log(data);
}

const newsFormRules = reactive({
    content:[{ required: true, message: "请输入内容", trigger: "blur" }],
})

const submitForm = () => {
    newsFormRef.value.validate(async(valid) => {
        if(valid) {
            console.log("newsForm",newsForm);
            const res = await axios.post("/wxapi/notice/add",newsForm);
            if(res.data.code == 200) {
                ElMessage.success("添加成功");
                // router.push('/newsManage/newsList');
            }else {
                ElMessage.error("添加失败");
            }
        }
    })
}
</script>

<style lang="scss" scoped>
.cover {
  width: 178px;
  height: 178px;
}
</style>